home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / doom / quake2.zip / TF1_2SRC.ZIP / QUAKE / FORTRESS / SOURCE / CLIENT.QC < prev    next >
Text File  |  1996-09-09  |  40KB  |  1,774 lines

  1.  
  2. // prototypes
  3. void () W_WeaponFrame;
  4. void() W_SetCurrentAmmo;
  5. void() player_pain;
  6. void() player_stand1;
  7. void (vector org) spawn_tfog;
  8. void (vector org, entity death_owner) spawn_tdeath;
  9.  
  10. float    modelindex_eyes, modelindex_player;
  11.  
  12. // TeamFortress prototypes
  13. void() TeamFortress_MOTD;
  14. void() TeamFortress_CheckTeamCheats;
  15. float(float tno) TeamFortress_TeamGetColor;
  16. void() TeamFortress_PrintClassName;
  17. void() TeamFortress_RemoveTimers;
  18. void() TeamFortress_ShowTF;
  19.  
  20. /*
  21. =============================================================================
  22.  
  23.                 LEVEL CHANGING / INTERMISSION
  24.  
  25. =============================================================================
  26. */
  27.  
  28. float    intermission_running;
  29. float    intermission_exittime;
  30.  
  31. /*QUAKED info_intermission (1 0.5 0.5) (-16 -16 -16) (16 16 16)
  32. This is the camera point for the intermission.
  33. Use mangle instead of angle, so you can set pitch or roll as well as yaw.  'pitch roll yaw'
  34. */
  35. void() info_intermission =
  36. {
  37. };
  38.  
  39.  
  40.  
  41. void() SetChangeParms =
  42. {
  43. // remove items
  44.     self.items = self.items - (self.items & 
  45.     (IT_KEY1 | IT_KEY2 | IT_INVISIBILITY | IT_INVULNERABILITY | IT_SUIT | IT_QUAD) );
  46.     
  47. // cap super health
  48.     if (self.health > 100)
  49.         self.health = 100;
  50.     if (self.health < 50)
  51.         self.health = 50;
  52.     parm1 = self.items;
  53.     parm2 = self.health;
  54.     parm3 = self.armorvalue;
  55.     if (self.ammo_shells < 25)
  56.         parm4 = 25;
  57.     else
  58.         parm4 = self.ammo_shells;
  59.     parm5 = self.ammo_nails;
  60.     parm6 = self.ammo_rockets;
  61.     parm7 = self.ammo_cells;
  62.     parm8 = self.weapon;
  63.     parm9 = self.armortype * 100;
  64.  
  65.     // TeamFortress Parameters
  66.     parm10 = toggleflags;  // Store the global ToggleFlag settings
  67.     parm11 = 0;              // Random Playerclass
  68.     parm12 = 0;
  69.     if (toggleflags & TFLAG_CLASS_PERSIST)        
  70.     {
  71.         if (self.tfstate & TFSTATE_RANDOMPC)
  72.         {
  73.             parm11 = (parm11 | TFSTATE_RANDOMPC);
  74.             self.playerclass = 1 + floor(random() * (PC_RANDOM - 1));
  75.         }
  76.  
  77.         parm12 = self.playerclass;                // save the playerclass between levels in parm12
  78.     }                                            // if the toggleflag CLASS_PERSIST is set
  79. };
  80.  
  81. void() SetNewParms =
  82. {
  83.     parm1 = IT_SHOTGUN | IT_AXE;
  84.     parm2 = 100;
  85.     parm3 = 0;
  86.     parm4 = 25;
  87.     parm5 = 0;
  88.     parm6 = 0;
  89.     parm6 = 0;
  90.     parm8 = 1;
  91.     parm9 = 0;
  92.  
  93.     // TeamFortress Parameters
  94.     parm10 = 0;
  95.     parm11 = 0;
  96.     parm12 = 0;
  97. };
  98.  
  99. void() DecodeLevelParms =
  100. {
  101.     local string st;
  102.  
  103.     if (serverflags)
  104.     {
  105.         if (world.model == "maps/start.bsp")
  106.             SetNewParms ();        // take away all stuff on starting new episode
  107.     }
  108.     
  109.     self.items = parm1;
  110.     self.health = parm2;
  111.     self.armorvalue = parm3;
  112.     self.ammo_shells = parm4;
  113.     self.ammo_nails = parm5;
  114.     self.ammo_rockets = parm6;
  115.     self.ammo_cells = parm7;
  116.     self.weapon = parm8;
  117.     self.armortype = parm9 * 0.01;
  118.  
  119.     // TeamFortress Parameters
  120.     // Detect whether this is the first entrance into a map
  121.     if (toggleflags == 0)
  122.     {
  123.         toggleflags = parm10;
  124.  
  125.         // Is this a FortressMap?
  126.         if (find(world, classname, "info_tfdetect") != world)
  127.         {
  128.             // Turn on Fortressmap
  129.             toggleflags = (toggleflags | TFLAG_FORTRESSMAP);
  130.             // Turn on Teamplay
  131.             cvar_set("teamplay","1");
  132.         }
  133.         else
  134.             toggleflags = toggleflags - (toggleflags & TFLAG_FORTRESSMAP);
  135.  
  136.         toggleflags = (toggleflags | TFLAG_FIRSTENTRY);
  137.     }
  138.  
  139.     if (parm11)
  140.         self.tfstate = parm11;
  141.     if (self.playerclass == 0)
  142.         self.playerclass = parm12;
  143. };
  144.  
  145. /*
  146. ============
  147. FindIntermission
  148.  
  149. Returns the entity to view from
  150. ============
  151. */
  152. entity() FindIntermission =
  153. {
  154.     local    entity spot;
  155.     local    float cyc;
  156.  
  157. // look for info_intermission first
  158.     spot = find (world, classname, "info_intermission");
  159.     if (spot)
  160.     {    // pick a random one
  161.         cyc = random() * 1;
  162.  
  163.         // Following removed for the observer code
  164.         /*while (cyc > 1)
  165.         {
  166.             spot = find (spot, classname, "info_intermission");
  167.             if (!spot)
  168.                 spot = find (spot, classname, "info_intermission");
  169.             cyc = cyc - 1;
  170.         }*/
  171.  
  172.         return spot;
  173.     }
  174.  
  175. // then look for the start position
  176.     spot = find (world, classname, "info_player_start");
  177.     if (spot)
  178.         return spot;
  179.  
  180. // then look through the deathmatch starts
  181.     spot = find (world, classname, "info_player_deathmatch");
  182.     if (spot)
  183.     {    
  184.         // pick a random one
  185.         cyc = random() * 6;
  186.         while (cyc > 1)
  187.         {
  188.             spot = find (spot, classname, "info_player_deathmatch");
  189.             if (!spot)
  190.                 spot = find (spot, classname, "info_player_deathmatch");
  191.             cyc = cyc - 1;
  192.         }
  193.         return spot;
  194.     }
  195.     
  196. // testinfo_player_start is only found in regioned levels
  197.     spot = find (world, classname, "testplayerstart");
  198.     if (spot)
  199.         return spot;
  200.     
  201.     objerror ("FindIntermission: no spot");
  202. };
  203.  
  204. /*===========================
  205. FindNextIntermission
  206.  
  207. returns the next intermission point
  208. ===========================*/
  209. entity (entity start_point) FindNextIntermission =
  210. {
  211.     local    entity spot;
  212.     local    float cyc;
  213.  
  214.     if (deathmatch)
  215.     {
  216.     // look through info_intermission first
  217.         if (start_point.classname == "info_intermission" || start_point == world)
  218.         {
  219.             spot = find (start_point, classname, "info_intermission");
  220.             if (spot)
  221.                 return spot;
  222.             else
  223.                 start_point = world;
  224.         }
  225.  
  226.  
  227.     // then look through the deathmatch starts
  228.         if (start_point.classname == "info_player_deathmatch" || start_point == world)
  229.         {
  230.             spot = find (start_point, classname, "info_player_deathmatch");
  231.             if (spot)
  232.                 return spot;
  233.         }
  234.  
  235.         // at the end of the list
  236.         spot = find (world, classname, "info_intermission");
  237.         if (spot)
  238.             return spot;
  239.  
  240.         spot = find (world, classname, "info_player_deathmatch");
  241.         if (spot)
  242.             return spot;
  243.     }
  244.     else // do not cycle though in co-op or single
  245.     {
  246.         spot = find (world, classname, "info_player_start");
  247.         if (spot)
  248.             return spot;
  249.     }
  250.  
  251.     // it should never reach this point
  252.     return FindIntermission();
  253.     
  254. };
  255.  
  256.  
  257. /*==================================================
  258.  
  259. TF_MovePlayer
  260. Moves the player to another intermission viewpoint
  261.  
  262. ====================================================*/
  263.  
  264. void() TF_MovePlayer =
  265. {
  266.     local entity place;
  267.  
  268.     place = FindNextIntermission(self.observer_list);
  269.  
  270.     self.observer_list = place;
  271.  
  272.     setorigin(self, place.origin + '0 0 1');
  273.     self.angles = place.angles;
  274.     self.fixangle = TRUE;        // turn this way immediately
  275.  
  276. };
  277.  
  278. string nextmap;
  279. void() GotoNextMap =
  280. {
  281.     if (cvar("samelevel"))    // if samelevel is set, stay on same level
  282.         changelevel (mapname);
  283.     else
  284.         changelevel (nextmap);
  285. };
  286.  
  287.  
  288. void() ExitIntermission =
  289. {
  290. // skip any text in deathmatch
  291.     if (deathmatch)
  292.     {
  293.         GotoNextMap ();
  294.         return;
  295.     }
  296.     
  297.     intermission_exittime = time + 1;
  298.     intermission_running = intermission_running + 1;
  299.  
  300. //
  301. // run some text if at the end of an episode
  302. //
  303.     if (intermission_running == 2)
  304.     {
  305.         if (world.model == "maps/e1m7.bsp")
  306.         {
  307.             WriteByte (MSG_ALL, SVC_CDTRACK);
  308.             WriteByte (MSG_ALL, 2);
  309.             WriteByte (MSG_ALL, 3);
  310.             if (!cvar("registered"))
  311.             {
  312.                 WriteByte (MSG_ALL, SVC_FINALE);
  313.                 WriteString (MSG_ALL, "As the corpse of the monstrous entity\nChthon sinks back into the lava whence\nit rose, you grip the Rune of Earth\nMagic tightly. Now that you have\nconquered the Dimension of the Doomed,\nrealm of Earth Magic, you are ready to\ncomplete your task in the other three\nhaunted lands of Quake. Or are you? If\nyou don't register Quake, you'll never\nknow what awaits you in the Realm of\nBlack Magic, the Netherworld, and the\nElder World!");
  314.             }
  315.             else
  316.             {
  317.                 WriteByte (MSG_ALL, SVC_FINALE);
  318.                 WriteString (MSG_ALL, "As the corpse of the monstrous entity\nChthon sinks back into the lava whence\nit rose, you grip the Rune of Earth\nMagic tightly. Now that you have\nconquered the Dimension of the Doomed,\nrealm of Earth Magic, you are ready to\ncomplete your task. A Rune of magic\npower lies at the end of each haunted\nland of Quake. Go forth, seek the\ntotality of the four Runes!");
  319.             }
  320.             return;
  321.         }
  322.         else if (world.model == "maps/e2m6.bsp")
  323.         {
  324.             WriteByte (MSG_ALL, SVC_CDTRACK);
  325.             WriteByte (MSG_ALL, 2);
  326.             WriteByte (MSG_ALL, 3);
  327.  
  328.             WriteByte (MSG_ALL, SVC_FINALE);
  329.             WriteString (MSG_ALL, "The Rune of Black Magic throbs evilly in\nyour hand and whispers dark thoughts\ninto your brain. You learn the inmost\nlore of the Hell-Mother; Shub-Niggurath!\nYou now know that she is behind all the\nterrible plotting which has led to so\nmuch death and horror. But she is not\ninviolate! Armed with this Rune, you\nrealize that once all four Runes are\ncombined, the gate to Shub-Niggurath's\nPit will open, and you can face the\nWitch-Goddess herself in her frightful\notherworld cathedral.");
  330.             return;
  331.         }
  332.         else if (world.model == "maps/e3m6.bsp")
  333.         {
  334.             WriteByte (MSG_ALL, SVC_CDTRACK);
  335.             WriteByte (MSG_ALL, 2);
  336.             WriteByte (MSG_ALL, 3);
  337.  
  338.             WriteByte (MSG_ALL, SVC_FINALE);
  339.             WriteString (MSG_ALL, "The charred viscera of diabolic horrors\nbubble viscously as you seize the Rune\nof Hell Magic. Its heat scorches your\nhand, and its terrible secrets blight\nyour mind. Gathering the shreds of your\ncourage, you shake the devil's shackles\nfrom your soul, and become ever more\nhard and determined to destroy the\nhideous creatures whose mere existence\nthreatens the souls and psyches of all\nthe population of Earth.");
  340.             return;
  341.         }
  342.         else if (world.model == "maps/e4m7.bsp")
  343.         {
  344.             WriteByte (MSG_ALL, SVC_CDTRACK);
  345.             WriteByte (MSG_ALL, 2);
  346.             WriteByte (MSG_ALL, 3);
  347.  
  348.             WriteByte (MSG_ALL, SVC_FINALE);
  349.             WriteString (MSG_ALL, "Despite the awful might of the Elder\nWorld, you have achieved the Rune of\nElder Magic, capstone of all types of\narcane wisdom. Beyond good and evil,\nbeyond life and death, the Rune\npulsates, heavy with import. Patient and\npotent, the Elder Being Shub-Niggurath\nweaves her dire plans to clear off all\nlife from the Earth, and bring her own\nfoul offspring to our world! For all the\ndwellers in these nightmare dimensions\nare her descendants! Once all Runes of\nmagic power are united, the energy\nbehind them will blast open the Gateway\nto Shub-Niggurath, and you can travel\nthere to foil the Hell-Mother's plots\nin person.");
  350.             return;
  351.         }
  352.  
  353.         GotoNextMap();
  354.     }
  355.     
  356.     if (intermission_running == 3)
  357.     {
  358.         if (!cvar("registered"))
  359.         {    // shareware episode has been completed, go to sell screen
  360.             WriteByte (MSG_ALL, SVC_SELLSCREEN);
  361.             return;
  362.         }
  363.         
  364.         if ( (serverflags&15) == 15)
  365.         {
  366.             WriteByte (MSG_ALL, SVC_FINALE);
  367.             WriteString (MSG_ALL, "Now, you have all four Runes. You sense\ntremendous invisible forces moving to\nunseal ancient barriers. Shub-Niggurath\nhad hoped to use the Runes Herself to\nclear off the Earth, but now instead,\nyou will use them to enter her home and\nconfront her as an avatar of avenging\nEarth-life. If you defeat her, you will\nbe remembered forever as the savior of\nthe planet. If she conquers, it will be\nas if you had never been born.");
  368.             return;
  369.         }
  370.         
  371.     }
  372.  
  373.     GotoNextMap();
  374. };
  375.  
  376. /*
  377. ============
  378. IntermissionThink
  379.  
  380. When the player presses attack or jump, change to the next level
  381. ============
  382. */
  383. void() IntermissionThink =
  384. {
  385.     if (time < intermission_exittime)
  386.         return;
  387.  
  388.     if (!self.button0 && !self.button1 && !self.button2)
  389.         return;
  390.     
  391.     ExitIntermission ();
  392. };
  393.  
  394. void() execute_changelevel =
  395. {
  396.     local entity    pos;
  397.  
  398.     intermission_running = 1;
  399.     
  400. // enforce a wait time before allowing changelevel
  401.     if (deathmatch)
  402.         intermission_exittime = time + 5;
  403.     else
  404.         intermission_exittime = time + 2;
  405.  
  406.     WriteByte (MSG_ALL, SVC_CDTRACK);
  407.     WriteByte (MSG_ALL, 3);
  408.     WriteByte (MSG_ALL, 3);
  409.     
  410.     pos = FindIntermission ();
  411.  
  412.     other = find (world, classname, "player");
  413.     while (other != world)
  414.     {
  415.         other.view_ofs = '0 0 0';
  416.         other.angles = other.v_angle = pos.mangle;
  417.         other.fixangle = TRUE;        // turn this way immediately
  418.         other.nextthink = time + 0.5;
  419.         other.takedamage = DAMAGE_NO;
  420.         other.solid = SOLID_NOT;
  421.         other.movetype = MOVETYPE_NONE;
  422.         other.modelindex = 0;
  423.         setorigin (other, pos.origin);
  424.         other = find (other, classname, "player");
  425.     }    
  426.  
  427.     WriteByte (MSG_ALL, SVC_INTERMISSION);
  428. };
  429.  
  430.  
  431. void() changelevel_touch =
  432. {
  433.     local entity    pos;
  434.  
  435.     if (other.classname != "player")
  436.         return;
  437.  
  438.     if (cvar("noexit"))
  439.     {
  440.         T_Damage (other, self, self, 50000);
  441.         return;
  442.     }
  443.     bprint (other.netname);
  444.     bprint (" exited the level\n");
  445.     
  446.     nextmap = self.map;
  447.  
  448.     SUB_UseTargets ();
  449.  
  450.     if ( (self.spawnflags & 1) && (deathmatch == 0) )
  451.     {    // NO_INTERMISSION
  452.         GotoNextMap();
  453.         return;
  454.     }
  455.     
  456.     self.touch = SUB_Null;
  457.  
  458. // we can't move people right now, because touch functions are called
  459. // in the middle of C movement code, so set a think time to do it
  460.     self.think = execute_changelevel;
  461.     self.nextthink = time + 0.1;
  462. };
  463.  
  464. /*QUAKED trigger_changelevel (0.5 0.5 0.5) ? NO_INTERMISSION
  465. When the player touches this, he gets sent to the map listed in the "map" variable.  Unless the NO_INTERMISSION flag is set, the view will go to the info_intermission spot and display stats.
  466. */
  467. void() trigger_changelevel =
  468. {
  469.     if (!self.map)
  470.         objerror ("changelevel trigger doesn't have map");
  471.     
  472.     InitTrigger ();
  473.     self.touch = changelevel_touch;
  474. };
  475.  
  476.  
  477. /*
  478. =============================================================================
  479.  
  480.                 PLAYER GAME EDGE FUNCTIONS
  481.  
  482. =============================================================================
  483. */
  484.  
  485. void() set_suicide_frame;
  486.  
  487. // called by ClientKill and DeadThink
  488. void() respawn =
  489. {
  490.     if (coop)
  491.     {
  492.         // if respawn delay is on, prevent respawn
  493.         if (self.weaponmode > time)
  494.                 return;
  495.  
  496.         // make a copy of the dead body for appearances sake
  497.         CopyToBodyQue (self);
  498.         // get the spawn parms as they were at level start
  499.         setspawnparms (self);
  500.         // respawn        
  501.         PutClientInServer ();
  502.     }
  503.     else if (deathmatch)
  504.     {
  505.         // if respawn delay is on, prevent respawn
  506.         if (self.weaponmode > time)
  507.             return;
  508.  
  509.         // make a copy of the dead body for appearances sake
  510.         CopyToBodyQue (self);
  511.         // set default spawn parms
  512.         SetNewParms ();
  513.         // respawn        
  514.         PutClientInServer ();
  515.     }
  516.     else
  517.     {    // restart the entire server
  518.         localcmd ("restart\n");
  519.     }
  520. };
  521.  
  522.  
  523. /*
  524. ============
  525. ClientKill
  526.  
  527. Player entered the suicide command
  528. ============
  529. */
  530. void() ClientKill =
  531. {
  532.     bprint (self.netname);
  533.     bprint (" suicides\n");
  534.     set_suicide_frame ();
  535.     self.modelindex = modelindex_player;
  536.     self.frags = self.frags - 2;    // extra penalty
  537.  
  538.     // Remove all timers for this player
  539.     TeamFortress_RemoveTimers();
  540.  
  541.     respawn ();
  542. };
  543.  
  544. float(vector v) CheckSpawnPoint =
  545. {
  546.     return FALSE;
  547. };
  548.  
  549. ////////////////////////////////////
  550. // FindTeamSpawnPoint
  551. //////////
  552. entity(float team_num) FindTeamSpawnPoint =
  553. {
  554.     local entity spot;
  555.  
  556.     spot = lastspawn;
  557.     
  558.     // search through until found or end-of-list
  559.     while (spot != world)
  560.     {
  561.         spot = find(spot, classname, "info_player_teamspawn");
  562.  
  563.         if (spot.team_no == team_num && spot != world)
  564.         {
  565.             lastspawn = spot;
  566.             return spot;
  567.         }
  568.     }
  569.  
  570.     // search through again
  571.     spot = find(world, classname, "info_player_teamspawn");
  572.     while (spot != world)
  573.     {
  574.         if (spot.team_no == team_num)
  575.         {
  576.             lastspawn = spot;
  577.             return spot;
  578.         }
  579.  
  580.         spot = find(spot, classname, "info_player_teamspawn");    
  581.     }
  582.  
  583.     // failure
  584.     return world;
  585. };
  586.  
  587.  
  588. /*
  589. ============
  590. SelectSpawnPoint
  591.  
  592. Returns the entity to spawn at
  593. ============
  594. */
  595. entity() SelectSpawnPoint =
  596. {
  597.     local    entity spot;
  598.     
  599.     // testinfo_player_start is only found in regioned levels
  600.     /*
  601.     spot = find (world, classname, "testplayerstart");
  602.     if (spot)
  603.         return spot;
  604.     */
  605.  
  606.     // If FortressMap option is on, we want to make the player spawn on a 
  607.     // spawnpoint marked as being one for his/her team.
  608.     // The team that owns a spawnpoint is kept in the spawnpoints's teamno
  609.     if (toggleflags & TFLAG_FORTRESSMAP && self.team_no != 0)
  610.     {
  611.         lastspawn = FindTeamSpawnPoint(self.team_no);
  612.  
  613.         if (lastspawn != world)
  614.             return lastspawn;
  615.         else
  616.             // failure to find a spawn point for that class
  617.             dprint("error: team spawn point not found\nusing deathmatch start instead.\n");
  618.     }
  619.  
  620.     // choose a info_player_deathmatch point
  621.     if (coop)
  622.     {
  623.         lastspawn = find(world, classname, "info_player_coop");
  624.         if (lastspawn == world)
  625.             lastspawn = find (lastspawn, classname, "info_player_start");
  626.         if (lastspawn != world)
  627.             return lastspawn;
  628.     }
  629.     else if (deathmatch)
  630.     {
  631.         lastspawn = find(world, classname, "info_player_deathmatch");
  632.  
  633.         if (lastspawn == world)
  634.             lastspawn = find (lastspawn, classname, "info_player_deathmatch");
  635.         else
  636.             return lastspawn;
  637.     }
  638.  
  639.     if (serverflags)
  640.     {    // return with a rune to start
  641.         spot = find (world, classname, "info_player_start2");
  642.         if (spot)
  643.             return spot;
  644.     }
  645.     
  646.     spot = find (world, classname, "info_player_start");
  647.     if (!spot)
  648.         error ("PutClientInServer: no info_player_start on level");
  649.     
  650.     return spot;
  651. };
  652.  
  653. /*
  654. ===========
  655. PutClientInServer
  656.  
  657. called each time a player is spawned
  658. ============
  659. */
  660. void() DecodeLevelParms;
  661. void() PlayerDie;
  662. void() TeamFortress_SetHealth;
  663. void() TeamFortress_SetEquipment;
  664. void() TeamFortress_SetSpeed;
  665. void() TeamFortress_SetSkin;
  666.  
  667. void() PutClientInServer =
  668. {
  669.     local    entity spot;
  670.  
  671.     self.classname = "player";
  672.     self.health = 100;
  673.     self.takedamage = DAMAGE_AIM;
  674.     self.solid = SOLID_SLIDEBOX;
  675.     self.movetype = MOVETYPE_WALK;
  676.     self.show_hostile = 0;
  677.     self.max_health = 100;
  678.     self.flags = FL_CLIENT;
  679.     self.air_finished = time + 12;
  680.     self.dmg = 2;           // initial water damage
  681.     self.super_damage_finished = 0;
  682.     self.radsuit_finished = 0;
  683.     self.invisible_finished = 0;
  684.     self.invincible_finished = 0;
  685.     self.effects = 0;
  686.     self.invincible_time = 0;
  687.  
  688.     self.reload_shotgun = 0;
  689.     self.reload_super_shotgun = 0;
  690.     self.reload_grenade_launcher = 0;
  691.     self.reload_rocket_launcher = 0;
  692.  
  693.     DecodeLevelParms ();
  694.  
  695.     // Reset all tfstate flags, except for RANDOMPC
  696.     if (self.tfstate & TFSTATE_RANDOMPC)
  697.     {
  698.         self.playerclass = 1 + floor(random() * (PC_RANDOM - 1));
  699.         self.tfstate = TFSTATE_RANDOMPC;
  700.     }
  701.     else
  702.         self.tfstate = 0;
  703.  
  704.     // Display the Player's Class
  705.     TeamFortress_PrintClassName();
  706.     // Set the weapons and ammo for the player based on class
  707.     TeamFortress_SetEquipment();
  708.     // Set the health for the player based on class
  709.     TeamFortress_SetHealth();
  710.     // Set the speed for the player based on class
  711.     TeamFortress_SetSpeed();
  712.     // Set the skin for the player based on class
  713.     TeamFortress_SetSkin();
  714.  
  715.     W_SetCurrentAmmo ();
  716.  
  717.     self.attack_finished = time;
  718.     self.th_pain = player_pain;
  719.     self.th_die = PlayerDie;
  720.     
  721.     self.deadflag = DEAD_NO;
  722. // pausetime is set by teleporters to keep the player from moving a while
  723.     self.pausetime = 0;
  724.     
  725.     spot = SelectSpawnPoint ();
  726.  
  727.     self.observer_list = spot;
  728.     self.origin = spot.origin + '0 0 1';
  729.     self.angles = spot.angles;
  730.     self.fixangle = TRUE;        // turn this way immediately
  731.  
  732. // oh, this is a hack!
  733.     setmodel (self, "progs/eyes.mdl");
  734.     modelindex_eyes = self.modelindex;
  735.  
  736.     setmodel (self, "progs/player.mdl");
  737.     modelindex_player = self.modelindex;
  738.  
  739.     if (self.playerclass == PC_UNDEFINED)
  740.         setmodel (self, "");
  741.  
  742.     setsize (self, VEC_HULL_MIN, VEC_HULL_MAX);
  743.     
  744.     self.view_ofs = '0 0 22';
  745.  
  746.     player_stand1 ();
  747.     
  748.     if (deathmatch || coop)
  749.     {
  750.         makevectors(self.angles);
  751.         spawn_tfog (self.origin + v_forward*20);
  752.     }
  753.  
  754.     spawn_tdeath (self.origin, self);
  755. };
  756.  
  757.  
  758. /*
  759. =============================================================================
  760.  
  761.                 QUAKED FUNCTIONS
  762.  
  763. =============================================================================
  764. */
  765.  
  766.  
  767. /*QUAKED info_player_start (1 0 0) (-16 -16 -24) (16 16 24)
  768. The normal starting point for a level.
  769. */
  770. void() info_player_start =
  771. {
  772. };
  773.  
  774.  
  775. /*QUAKED info_player_start2 (1 0 0) (-16 -16 -24) (16 16 24)
  776. Only used on start map for the return point from an episode.
  777. */
  778. void() info_player_start2 =
  779. {
  780. };
  781.  
  782.  
  783. /*
  784. saved out by quaked in region mode
  785. */
  786. void() testplayerstart =
  787. {
  788. };
  789.  
  790. /*QUAKED info_player_deathmatch (1 0 1) (-16 -16 -24) (16 16 24)
  791. potential spawning position for deathmatch games
  792. */
  793. void() info_player_deathmatch =
  794. {
  795. };
  796.  
  797. /*QUAKED info_player_coop (1 0 1) (-16 -16 -24) (16 16 24)
  798. potential spawning position for coop games
  799. */
  800. void() info_player_coop =
  801. {
  802. };
  803.  
  804. /*
  805. ===============================================================================
  806.  
  807. RULES
  808.  
  809. ===============================================================================
  810. */
  811.  
  812. void(entity c) PrintClientScore =
  813. {
  814.     if (c.frags > -10 && c.frags < 0)
  815.         bprint (" ");
  816.     else if (c.frags >= 0)
  817.     {
  818.         if (c.frags < 100)
  819.             bprint (" ");
  820.         if (c.frags < 10)
  821.             bprint (" ");
  822.     }
  823.     bprint (ftos(c.frags));
  824.     bprint (" ");
  825.     bprint (c.netname);
  826.     bprint ("\n");
  827. };
  828.  
  829. void() DumpScore =
  830. {
  831.     local entity    e, sort, walk;
  832.  
  833.     if (world.chain)
  834.         error ("DumpScore: world.chain is set");
  835.  
  836. // build a sorted lis
  837.     e = find(world, classname, "player");
  838.     sort = world;
  839.     while (e)
  840.     {
  841.         if (!sort)
  842.         {
  843.             sort = e;
  844.             e.chain = world;
  845.         }
  846.         else
  847.         {
  848.             if (e.frags > sort.frags)
  849.             {
  850.                 e.chain = sort;
  851.                 sort = e;
  852.             }
  853.             else
  854.             {
  855.                 walk = sort;
  856.                 do
  857.                 {
  858.                     if (!walk.chain)
  859.                     {
  860.                         e.chain = world;
  861.                         walk.chain = e;
  862.                     }
  863.                     else if (walk.chain.frags < e.frags)
  864.                     {
  865.                         e.chain = walk.chain;
  866.                         walk.chain = e;
  867.                     }
  868.                     else
  869.                         walk = walk.chain;
  870.                 } while (walk.chain != e);
  871.             }
  872.         }
  873.         
  874.         e = find(e, classname, "player");
  875.     }
  876.  
  877. // print the list
  878.     
  879.     bprint ("\n");    
  880.     while (sort)
  881.     {
  882.         PrintClientScore (sort);
  883.         sort = sort.chain;
  884.     }
  885.     bprint ("\n");
  886. };
  887.  
  888. /*
  889. go to the next level for deathmatch
  890. */
  891. void() NextLevel =
  892. {
  893.     local entity o;
  894.  
  895.     // find a trigger changelevel
  896.     o = find(world, classname, "trigger_changelevel");
  897.     if (!o || mapname == "start")
  898.     {    // go back to same map if no trigger_changelevel
  899.         o = spawn();
  900.         o.map = mapname;
  901.     }
  902.  
  903.     nextmap = o.map;
  904.     
  905.     if (o.nextthink < time)
  906.     {
  907.         o.think = execute_changelevel;
  908.         o.nextthink = time + 0.1;
  909.     }
  910. };
  911.  
  912. /*
  913. ============
  914. CheckRules
  915.  
  916. Exit deathmatch games upon conditions
  917. ============
  918. */
  919. void() CheckRules =
  920. {
  921.     local    float        timelimit;
  922.     local    float        fraglimit;
  923.     
  924.     if (gameover)    // someone else quit the game already
  925.         return;
  926.         
  927.     timelimit = cvar("timelimit") * 60;
  928.     fraglimit = cvar("fraglimit");
  929.     
  930.     if (timelimit && time >= timelimit)
  931.     {
  932.         NextLevel ();
  933. /*
  934.         gameover = TRUE;
  935.         bprint ("\n\n\n==============================\n");
  936.         bprint ("game exited after ");
  937.         bprint (ftos(timelimit/60));
  938.         bprint (" minutes\n");
  939.         DumpScore ();
  940.         localcmd ("killserver\n");
  941. */
  942.         return;
  943.     }
  944.     
  945.     if (fraglimit && self.frags >= fraglimit)
  946.     {
  947.         NextLevel ();
  948. /*
  949.         gameover = TRUE;
  950.         bprint ("\n\n\n==============================\n");
  951.         bprint ("game exited after ");
  952.         bprint (ftos(self.frags));
  953.         bprint (" frags\n");
  954.         DumpScore ();
  955.         localcmd ("killserver\n");
  956. */
  957.         return;
  958.     }    
  959. };
  960.  
  961. //============================================================================
  962.  
  963. void() PlayerDeathThink =
  964. {
  965.     local entity    old_self;
  966.     local float        forward;
  967.  
  968.     if ((self.flags & FL_ONGROUND))
  969.     {
  970.         forward = vlen (self.velocity);
  971.         forward = forward - 20;
  972.         if (forward <= 0)
  973.             self.velocity = '0 0 0';
  974.         else    
  975.             self.velocity = forward * normalize(self.velocity);
  976.     }
  977.  
  978. // wait for all buttons released
  979.     if (self.deadflag == DEAD_DEAD)
  980.     {
  981.         if (self.button2 || self.button1 || self.button0)
  982.             return;
  983.         self.deadflag = DEAD_RESPAWNABLE;
  984.         return;
  985.     }
  986.  
  987. // wait for any button down
  988.     if (!self.button2 && !self.button1 && !self.button0)
  989.         return;
  990.  
  991.     self.button0 = 0;
  992.     self.button1 = 0;
  993.     self.button2 = 0;
  994.     respawn();
  995. };
  996.  
  997.  
  998. void() PlayerJump =
  999. {
  1000.     local vector start, end;
  1001.     
  1002.     if (self.flags & FL_WATERJUMP)
  1003.         return;
  1004.     
  1005.     if (self.waterlevel >= 2)
  1006.     {
  1007.         if (self.watertype == CONTENT_WATER)
  1008.             self.velocity_z = 100;
  1009.         else if (self.watertype == CONTENT_SLIME)
  1010.             self.velocity_z = 80;
  1011.         else
  1012.             self.velocity_z = 50;
  1013.  
  1014. // play swiming sound
  1015.         if (self.swim_flag < time)
  1016.         {
  1017.             self.swim_flag = time + 1;
  1018.             if (random() < 0.5)
  1019.                 sound (self, CHAN_BODY, "misc/water1.wav", 1, ATTN_NORM);
  1020.             else
  1021.                 sound (self, CHAN_BODY, "misc/water2.wav", 1, ATTN_NORM);
  1022.         }
  1023.  
  1024.         return;
  1025.     }
  1026.  
  1027.     if (!(self.flags & FL_ONGROUND))
  1028.         return;
  1029.  
  1030.     if ( !(self.flags & FL_JUMPRELEASED) )
  1031.         return;        // don't pogo stick
  1032.  
  1033.     self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
  1034.  
  1035.     self.flags = self.flags - FL_ONGROUND;    // don't stairwalk
  1036.     
  1037.     self.button2 = 0;
  1038. // player jumping sound
  1039.     sound (self, CHAN_BODY, "player/plyrjmp8.wav", 1, ATTN_NORM);
  1040.     self.velocity_z = self.velocity_z + 270;
  1041. };
  1042.  
  1043.  
  1044. /*
  1045. ===========
  1046. WaterMove
  1047.  
  1048. ============
  1049. */
  1050. .float    dmgtime;
  1051.  
  1052. void() WaterMove =
  1053. {
  1054. //dprint (ftos(self.waterlevel));
  1055.     if (self.movetype == MOVETYPE_NOCLIP)
  1056.         return;
  1057.     if (self.health < 0)
  1058.         return;
  1059.  
  1060.     if (self.waterlevel != 3)
  1061.     {
  1062.         if (self.air_finished < time)
  1063.             sound (self, CHAN_VOICE, "player/gasp2.wav", 1, ATTN_NORM);
  1064.         else if (self.air_finished < time + 9)
  1065.             sound (self, CHAN_VOICE, "player/gasp1.wav", 1, ATTN_NORM);
  1066.         self.air_finished = time + 12;
  1067.         self.dmg = 2;
  1068.     }
  1069.     else if (self.air_finished < time)
  1070.     {    // drown!
  1071.         if (self.pain_finished < time)
  1072.         {
  1073.             self.dmg = self.dmg + 2;
  1074.             if (self.dmg > 15)
  1075.                 self.dmg = 10;
  1076.             TF_T_Damage (self, world, world, self.dmg, TF_TD_IGNOREARMOUR);
  1077.             self.pain_finished = time + 1;
  1078.         }
  1079.     }
  1080.     
  1081.     if (!self.waterlevel)
  1082.     {
  1083.         if (self.flags & FL_INWATER)
  1084.         {    
  1085.             // play leave water sound
  1086.             sound (self, CHAN_BODY, "misc/outwater.wav", 1, ATTN_NORM);
  1087.             self.flags = self.flags - FL_INWATER;
  1088.         }
  1089.         return;
  1090.     }
  1091.  
  1092.     if (self.watertype == CONTENT_LAVA)
  1093.     {    // do damage
  1094.         if (self.dmgtime < time)
  1095.         {
  1096.             if (self.radsuit_finished > time)
  1097.                 self.dmgtime = time + 1;
  1098.             else
  1099.                 self.dmgtime = time + 0.2;
  1100.  
  1101.             T_Damage (self, world, world, 10*self.waterlevel);
  1102.         }
  1103.     }
  1104.     else if (self.watertype == CONTENT_SLIME)
  1105.     {    // do damage
  1106.         if (self.dmgtime < time && self.radsuit_finished < time)
  1107.         {
  1108.             self.dmgtime = time + 1;
  1109.             T_Damage (self, world, world, 4*self.waterlevel);
  1110.         }
  1111.     }
  1112.     
  1113.     if ( !(self.flags & FL_INWATER) )
  1114.     {    
  1115.  
  1116. // player enter water sound
  1117.  
  1118.         if (self.watertype == CONTENT_LAVA)
  1119.             sound (self, CHAN_BODY, "player/inlava.wav", 1, ATTN_NORM);
  1120.         if (self.watertype == CONTENT_WATER)
  1121.             sound (self, CHAN_BODY, "player/inh2o.wav", 1, ATTN_NORM);
  1122.         if (self.watertype == CONTENT_SLIME)
  1123.             sound (self, CHAN_BODY, "player/slimbrn2.wav", 1, ATTN_NORM);
  1124.  
  1125.         self.flags = self.flags + FL_INWATER;
  1126.         self.dmgtime = 0;
  1127.     }
  1128.     
  1129.     if (! (self.flags & FL_WATERJUMP) )
  1130.         self.velocity = self.velocity - 0.8*self.waterlevel*frametime*self.velocity;
  1131. };
  1132.  
  1133. void() CheckWaterJump =
  1134. {
  1135.     local vector start, end;
  1136.  
  1137. // check for a jump-out-of-water
  1138.     makevectors (self.angles);
  1139.     start = self.origin;
  1140.     start_z = start_z + 8; 
  1141.     v_forward_z = 0;
  1142.     normalize(v_forward);
  1143.     end = start + v_forward*24;
  1144.     traceline (start, end, TRUE, self);
  1145.     if (trace_fraction < 1)
  1146.     {    // solid at waist
  1147.         start_z = start_z + self.maxs_z - 8;
  1148.         end = start + v_forward*24;
  1149.         self.movedir = trace_plane_normal * -50;
  1150.         traceline (start, end, TRUE, self);
  1151.         if (trace_fraction == 1)
  1152.         {    // open at eye level
  1153.             self.flags = self.flags | FL_WATERJUMP;
  1154.             self.velocity_z = 225;
  1155.             self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
  1156.             self.teleport_time = time + 2;    // safety net
  1157.             return;
  1158.         }
  1159.     }
  1160. };
  1161.  
  1162.  
  1163. /*
  1164. ================
  1165. PlayerPreThink
  1166.  
  1167. Called every frame before physics are run
  1168. ================
  1169. */
  1170. void() PlayerPreThink =
  1171. {
  1172.     local    float    mspeed, aspeed;
  1173.     local    float    r;
  1174.  
  1175.     if (intermission_running)
  1176.     {
  1177.         IntermissionThink ();    // otherwise a button could be missed between
  1178.         return;                    // the think tics
  1179.     }
  1180.  
  1181.     if (self.view_ofs == '0 0 0')
  1182.         return;        // intermission or finale
  1183.  
  1184.     makevectors (self.v_angle);        // is this still used
  1185.  
  1186.     CheckRules ();
  1187.     WaterMove ();
  1188.  
  1189.     if (self.waterlevel == 2)
  1190.         CheckWaterJump ();
  1191.  
  1192.     if (self.deadflag >= DEAD_DEAD)
  1193.     {
  1194.         PlayerDeathThink ();
  1195.         return;
  1196.     }
  1197.     
  1198.     if (self.deadflag == DEAD_DYING)
  1199.         return;    // dying, so do nothing
  1200.  
  1201.     if (self.button2)
  1202.     {
  1203.         PlayerJump ();
  1204.     }
  1205.     else
  1206.         self.flags = self.flags | FL_JUMPRELEASED;
  1207.  
  1208. // teleporters can force a non-moving pause time    
  1209.     if (time < self.pausetime)
  1210.         self.velocity = '0 0 0';
  1211. };
  1212.     
  1213. /*
  1214. ================
  1215. CheckPowerups
  1216.  
  1217. Check for turning off powerups
  1218. ================
  1219. */
  1220. void() CheckPowerups =
  1221. {
  1222.     if (self.health <= 0)
  1223.         return;
  1224.  
  1225. // invisibility
  1226.     if (self.invisible_finished)
  1227.     {
  1228. // sound and screen flash when items starts to run out
  1229.         if (self.invisible_sound < time)
  1230.         {
  1231.             sound (self, CHAN_AUTO, "items/inv3.wav", 0.5, ATTN_IDLE);
  1232.             self.invisible_sound = time + ((random() * 3) + 1);
  1233.         }
  1234.  
  1235.  
  1236.         if (self.invisible_finished < time + 3)
  1237.         {
  1238.             if (self.invisible_time == 1)
  1239.             {
  1240.                 sprint (self, "Ring of Shadows magic is fading\n");
  1241.                 stuffcmd (self, "bf\n");
  1242.                 sound (self, CHAN_AUTO, "items/inv2.wav", 1, ATTN_NORM);
  1243.                 self.invisible_time = time + 1;
  1244.             }
  1245.             
  1246.             if (self.invisible_time < time)
  1247.             {
  1248.                 self.invisible_time = time + 1;
  1249.                 stuffcmd (self, "bf\n");
  1250.             }
  1251.         }
  1252.  
  1253.         if (self.invisible_finished < time)
  1254.         {    // just stopped
  1255.             self.items = self.items - IT_INVISIBILITY;
  1256.             self.invisible_finished = 0;
  1257.             self.invisible_time = 0;
  1258.         }
  1259.         
  1260.     // use the eyes
  1261.         self.frame = 0;
  1262.         self.modelindex = modelindex_eyes;
  1263.     }
  1264.     else
  1265.         self.modelindex = modelindex_player;    // don't use eyes
  1266.  
  1267. // invincibility
  1268.     if (self.invincible_finished)
  1269.     {
  1270. // sound and screen flash when items starts to run out
  1271.         if (self.invincible_finished < time + 3)
  1272.         {
  1273.             if (self.invincible_time == 1)
  1274.             {
  1275.                 sprint (self, "Protection is almost burned out\n");
  1276.                 stuffcmd (self, "bf\n");
  1277.                 sound (self, CHAN_AUTO, "items/protect2.wav", 1, ATTN_NORM);
  1278.                 self.invincible_time = time + 1;
  1279.             }
  1280.             
  1281.             if (self.invincible_time < time)
  1282.             {
  1283.                 self.invincible_time = time + 1;
  1284.                 stuffcmd (self, "bf\n");
  1285.             }
  1286.         }
  1287.         
  1288.         if (self.invincible_finished < time)
  1289.         {    // just stopped
  1290.             self.items = self.items - IT_INVULNERABILITY;
  1291.             self.invincible_time = 0;
  1292.             self.invincible_finished = 0;
  1293.         }
  1294.         if (self.invincible_finished > time)
  1295.             self.effects = self.effects | EF_DIMLIGHT;
  1296.         else
  1297.             self.effects = self.effects - (self.effects & EF_DIMLIGHT);
  1298.     }
  1299.  
  1300. // super damage
  1301.     if (self.super_damage_finished)
  1302.     {
  1303.  
  1304. // sound and screen flash when items starts to run out
  1305.  
  1306.         if (self.super_damage_finished < time + 3)
  1307.         {
  1308.             if (self.super_time == 1)
  1309.             {
  1310.                 sprint (self, "Quad Damage is wearing off\n");
  1311.                 stuffcmd (self, "bf\n");
  1312.                 sound (self, CHAN_AUTO, "items/damage2.wav", 1, ATTN_NORM);
  1313.                 self.super_time = time + 1;
  1314.             }      
  1315.             
  1316.             if (self.super_time < time)
  1317.             {
  1318.                 self.super_time = time + 1;
  1319.                 stuffcmd (self, "bf\n");
  1320.             }
  1321.         }
  1322.  
  1323.         if (self.super_damage_finished < time)
  1324.         {    // just stopped
  1325.             self.items = self.items - IT_QUAD;
  1326.             self.super_damage_finished = 0;
  1327.             self.super_time = 0;
  1328.         }
  1329.         if (self.super_damage_finished > time)
  1330.             self.effects = self.effects | EF_DIMLIGHT;
  1331.         else
  1332.             self.effects = self.effects - (self.effects & EF_DIMLIGHT);
  1333.     }    
  1334.  
  1335. // suit    
  1336.     if (self.radsuit_finished)
  1337.     {
  1338.         self.air_finished = time + 12;        // don't drown
  1339.  
  1340. // sound and screen flash when items starts to run out
  1341.         if (self.radsuit_finished < time + 3)
  1342.         {
  1343.             if (self.rad_time == 1)
  1344.             {
  1345.                 sprint (self, "Air supply in Biosuit expiring\n");
  1346.                 stuffcmd (self, "bf\n");
  1347.                 sound (self, CHAN_AUTO, "items/suit2.wav", 1, ATTN_NORM);
  1348.                 self.rad_time = time + 1;
  1349.             }
  1350.             
  1351.             if (self.rad_time < time)
  1352.             {
  1353.                 self.rad_time = time + 1;
  1354.                 stuffcmd (self, "bf\n");
  1355.             }
  1356.         }
  1357.  
  1358.         if (self.radsuit_finished < time)
  1359.         {    // just stopped
  1360.             self.items = self.items - IT_SUIT;
  1361.             self.rad_time = 0;
  1362.             self.radsuit_finished = 0;
  1363.         }
  1364.     }    
  1365.  
  1366. };
  1367.  
  1368.  
  1369. /*
  1370. ================
  1371. PlayerPostThink
  1372.  
  1373. Called every frame after physics are run
  1374. ================
  1375. */
  1376. void() PlayerPostThink =
  1377. {
  1378.     local    float    mspeed, aspeed;
  1379.     local    float    r;
  1380.  
  1381.     if (self.view_ofs == '0 0 0')
  1382.         return;        // intermission or finale
  1383.     if (self.deadflag)
  1384.         return;
  1385.         
  1386. // do weapon stuff
  1387.  
  1388.     W_WeaponFrame ();
  1389.  
  1390. // check to see if player landed and play landing sound    
  1391.     if ((self.jump_flag < -300) && (self.flags & FL_ONGROUND) && (self.health > 0))
  1392.     {
  1393.         if (self.watertype == CONTENT_WATER)
  1394.             sound (self, CHAN_BODY, "player/h2ojump.wav", 1, ATTN_NORM);
  1395.         else if (self.jump_flag < -650)
  1396.         {
  1397.             T_Damage (self, world, world, 5); 
  1398.             sound (self, CHAN_VOICE, "player/land2.wav", 1, ATTN_NORM);
  1399.             self.deathtype = "falling";
  1400.         }
  1401.         else
  1402.             sound (self, CHAN_VOICE, "player/land.wav", 1, ATTN_NORM);
  1403.  
  1404.         self.jump_flag = 0;
  1405.     }
  1406.  
  1407.     if (!(self.flags & FL_ONGROUND))
  1408.         self.jump_flag = self.velocity_z;
  1409.  
  1410.     CheckPowerups ();
  1411.  
  1412. // Check for Team Cheats
  1413.     TeamFortress_CheckTeamCheats();
  1414.  
  1415. // Display MOTD
  1416.     if (self.motd <= 22)
  1417.         TeamFortress_MOTD();
  1418. };
  1419.  
  1420.  
  1421. /*
  1422. ===========
  1423. ClientConnect
  1424.  
  1425. called when a player connects to a server
  1426. ============
  1427. */
  1428. void() ClientConnect =
  1429. {
  1430.     bprint (self.netname);
  1431.     bprint (" entered the game\n");
  1432.  
  1433.     // Set the MOTD on
  1434.     self.motd = 0;
  1435.  
  1436.     // a client connecting during an intermission can cause problems
  1437.     if (intermission_running)
  1438.         ExitIntermission ();
  1439. };
  1440.  
  1441.  
  1442. /*
  1443. ===========
  1444. ClientDisconnect
  1445.  
  1446. called when a player disconnects from a server
  1447. ============
  1448. */
  1449. void() ClientDisconnect =
  1450. {
  1451.     if (gameover)
  1452.         return;
  1453.     // if the level end trigger has been activated, just return
  1454.     // since they aren't *really* leaving
  1455.  
  1456.     // let everyone else know
  1457.     bprint (self.netname);
  1458.     bprint (" left the game with ");
  1459.     bprint (ftos(self.frags));
  1460.     bprint (" frags\n");
  1461.     sound (self, CHAN_BODY, "player/tornoff2.wav", 1, ATTN_NONE);
  1462.     set_suicide_frame ();
  1463. };
  1464.  
  1465. /*
  1466. ===========
  1467. ClientObituary
  1468.     
  1469. called when a player dies
  1470. ============
  1471. */
  1472. void(entity targ, entity attacker) ClientObituary =
  1473. {
  1474.     local    float rnum;
  1475.     local    string deathstring, deathstring2;
  1476.     rnum = random();
  1477.  
  1478.     if (targ.classname == "player")
  1479.     {
  1480.         if (attacker.classname == "teledeath")
  1481.         {
  1482.             bprint (targ.netname);
  1483.             bprint (" was telefragged by ");
  1484.             bprint (attacker.owner.netname);
  1485.             bprint ("\n");
  1486.  
  1487.             attacker.owner.frags = attacker.owner.frags + 1;
  1488.             return;
  1489.         }
  1490.  
  1491.         if (attacker.classname == "teledeath2")
  1492.         {
  1493.             bprint ("Satan's power deflects ");
  1494.             bprint (targ.netname);
  1495.             bprint ("'s telefrag\n");
  1496.  
  1497.             targ.frags = targ.frags - 1;
  1498.             return;
  1499.         }
  1500.  
  1501.         if (attacker.classname == "tfgoal")
  1502.         {
  1503.             bprint(targ.netname);
  1504.             bprint(attacker.killtarget);
  1505.             return;
  1506.         }
  1507.  
  1508.         if (attacker.classname == "player")
  1509.         {
  1510.             if (targ == attacker)
  1511.             {
  1512.                 // killed self
  1513.                 attacker.frags = attacker.frags - 1;
  1514.                 bprint (targ.netname);
  1515.                 
  1516.                 if (targ.tfstate & TFSTATE_ALTKILL)
  1517.                 {
  1518.                     if (targ.altkillweapon == AK_GRENADE)
  1519.                         bprint(" grenades himself\n");
  1520.                     if (targ.altkillweapon == AK_GRENADE_NAIL)
  1521.                         bprint(" hammers himself\n");
  1522.                     if (targ.altkillweapon == AK_GRENADE_MIRV)
  1523.                         bprint(" goes to pieces\n");
  1524.                     if (targ.altkillweapon == AK_DETPACK)
  1525.                         bprint(" set the detpack and forgot to run\n");
  1526.                     if (targ.altkillweapon == AK_BIOWEAPON)
  1527.                         bprint(" died impossibly!\n");
  1528.                     if (targ.altkillweapon == AK_MISSILE )
  1529.                     {
  1530.                         if (rnum)
  1531.                             bprint (" becomes bored with life\n");
  1532.                         else
  1533.                             bprint (" checks if his weapon is loaded\n");
  1534.                     }
  1535.                     if (targ.altkillweapon == AK_ORG_GRENADE )
  1536.                         bprint (" tries to put the pin back in\n");
  1537.                     return;
  1538.                 }
  1539.  
  1540.                 if (targ.weapon == 64 && targ.waterlevel > 1)
  1541.                 {
  1542.                     bprint (" discharges into the water.\n");
  1543.                     return;
  1544.                 }
  1545.             }
  1546.             else
  1547.             {
  1548.                 attacker.frags = attacker.frags + 1;
  1549.  
  1550.                 if (targ.tfstate & TFSTATE_ALTKILL)
  1551.                 {
  1552.                     if (targ.altkillweapon == AK_GRENADE)
  1553.                     {
  1554.                         deathstring = " surfs on a grenade from ";
  1555.                         deathstring2 = "\n";
  1556.                     }
  1557.                     if (targ.altkillweapon == AK_GRENADE_NAIL)
  1558.                     {
  1559.                         deathstring = " gets flayed by ";
  1560.                         deathstring2 = "'s nail grenade\n";
  1561.                     }
  1562.                     if (targ.altkillweapon == AK_GRENADE_MIRV)
  1563.                     {
  1564.                         deathstring = " gets spammed by ";
  1565.                         deathstring2 = "'s Mirv grenade\n";
  1566.                     }
  1567.                     if (targ.altkillweapon == AK_DETPACK)
  1568.                     {
  1569.                         deathstring = " reaches orbit via ";
  1570.                         deathstring2 = "'s detpack\n";
  1571.                     }
  1572.                     if (targ.altkillweapon == AK_BIOWEAPON)
  1573.                     {
  1574.                         deathstring = " dies from ";
  1575.                         deathstring2 = " 's mysterious tropical disease\n";            
  1576.                     }
  1577.                     if (targ.altkillweapon == AK_ORG_GRENADE)
  1578.                     {
  1579.                         deathstring = " eats ";
  1580.                         deathstring2 = "'s pineapple\n";
  1581.                         if (targ.health < -40)
  1582.                         {
  1583.                             deathstring = " was gibbed by ";
  1584.                             deathstring2 = "'s grenade\n";
  1585.                         }
  1586.                     }
  1587.                     if (targ.altkillweapon == AK_MISSILE)
  1588.                     {
  1589.                         deathstring = " rides ";
  1590.                         deathstring2 = "'s rocket\n";
  1591.                         if (targ.health < -40)
  1592.                         {
  1593.                             deathstring = " was gibbed by ";
  1594.                             deathstring2 = "'s rocket\n" ;
  1595.                         }
  1596.                     }
  1597.                 }
  1598.                 else
  1599.                 {
  1600.                     rnum = attacker.weapon;
  1601.                     if (rnum == IT_AXE)
  1602.                     {
  1603.                         deathstring = " was ax-murdered by ";
  1604.                         deathstring2 = "\n";
  1605.                     }
  1606.                     if (rnum == IT_SHOTGUN)
  1607.                     {
  1608.                         deathstring = " chewed on ";
  1609.                         deathstring2 = "'s boomstick\n";
  1610.                     }
  1611.                     if (rnum == IT_SUPER_SHOTGUN)
  1612.                     {
  1613.                         deathstring = " ate 2 loads of ";
  1614.                         deathstring2 = "'s buckshot\n";
  1615.                     }
  1616.                     if (rnum == IT_NAILGUN)
  1617.                     {
  1618.                         deathstring = " was nailed by ";
  1619.                         deathstring2 = "\n";
  1620.                     }
  1621.                     if (rnum == IT_SUPER_NAILGUN)
  1622.                     {
  1623.                         deathstring = " was punctured by ";
  1624.                         deathstring2 = "\n";
  1625.                     }
  1626.                     if (rnum == IT_LIGHTNING)
  1627.                     {
  1628.                         deathstring = " accepts ";
  1629.                         if (attacker.waterlevel > 1)
  1630.                             deathstring2 = "'s discharge\n";
  1631.                         else
  1632.                             deathstring2 = "'s shaft\n";
  1633.                     }
  1634.                     if (rnum == IT_EXTRA_WEAPON)
  1635.                     {
  1636.                         if (attacker.secondary_weapon == NIT_SNIPER_RIFLE)
  1637.                         {
  1638.                             deathstring = " succumbs to sniperfire from ";
  1639.                             deathstring2 = "\n";
  1640.                             if (targ.health < -40)
  1641.                             {
  1642.                                 deathstring = " gets a third eye from ";
  1643.                                 deathstring2 = "\n";
  1644.                             }
  1645.                         }
  1646.                         if (attacker.secondary_weapon == NIT_AUTO_RIFLE)
  1647.                         {
  1648.                             deathstring = " collects ";
  1649.                             deathstring2 = "'s bullet spray.\n";
  1650.                         }
  1651.                         if (attacker.secondary_weapon == NIT_ASSAULT_CANNON)
  1652.                         {
  1653.                             deathstring = " gets sawn in half by ";
  1654.                             deathstring2 = "\n";
  1655.                         }
  1656.                     }
  1657.                 }
  1658.                 bprint (targ.netname);
  1659.                 bprint (deathstring);
  1660.                 bprint (attacker.netname);
  1661.                 bprint (deathstring2);
  1662.             }
  1663.             return;
  1664.         }
  1665.         else
  1666.         {
  1667.             targ.frags = targ.frags - 1;        // killed self
  1668.             rnum = targ.watertype;
  1669.  
  1670.             bprint (targ.netname);
  1671.             if (rnum == -3)
  1672.             {
  1673.                 if (random() < 0.5)
  1674.                     bprint (" sleeps with the fishes\n");
  1675.                 else
  1676.                     bprint (" sucks it down\n");
  1677.                 return;
  1678.             }
  1679.             else if (rnum == -4)
  1680.             {
  1681.                 if (random() < 0.5)
  1682.                     bprint (" gulped a load of slime\n");
  1683.                 else
  1684.                     bprint (" can't exist on slime alone\n");
  1685.                 return;
  1686.             }
  1687.             else if (rnum == -5)
  1688.             {
  1689.                 if (targ.health < -15)
  1690.                 {
  1691.                     bprint (" burst into flames\n");
  1692.                     return;
  1693.                 }
  1694.                 if (random() < 0.5)
  1695.                     bprint (" turned into hot slag\n");
  1696.                 else
  1697.                     bprint (" visits the Volcano God\n");
  1698.                 return;
  1699.             }
  1700.  
  1701.             if (attacker.flags & FL_MONSTER)
  1702.             {
  1703.                 if (attacker.classname == "monster_army")
  1704.                     bprint (" was shot by a Grunt\n");
  1705.                 if (attacker.classname == "monster_demon1")
  1706.                     bprint (" was eviscerated by a Fiend\n");
  1707.                 if (attacker.classname == "monster_dog")
  1708.                     bprint (" was mauled by a Rottweiler\n");
  1709.                 if (attacker.classname == "monster_dragon")
  1710.                     bprint (" was fried by a Dragon\n");
  1711.                 if (attacker.classname == "monster_enforcer")
  1712.                     bprint (" was blasted by an Enforcer\n");
  1713.                 if (attacker.classname == "monster_fish")
  1714.                     bprint (" was fed to the Rotfish\n");
  1715.                 if (attacker.classname == "monster_hell_knight")
  1716.                     bprint (" was slain by a Death Knight\n");
  1717.                 if (attacker.classname == "monster_knight")
  1718.                     bprint (" was slashed by a Knight\n");
  1719.                 if (attacker.classname == "monster_ogre")
  1720.                     bprint (" was destroyed by an Ogre\n");
  1721.                 if (attacker.classname == "monster_oldone")
  1722.                     bprint (" became one with Shub-Niggurath\n");
  1723.                 if (attacker.classname == "monster_shalrath")
  1724.                     bprint (" was exploded by a Vore\n");
  1725.                 if (attacker.classname == "monster_shambler")
  1726.                     bprint (" was smashed by a Shambler\n");
  1727.                 if (attacker.classname == "monster_tarbaby")
  1728.                     bprint (" was slimed by a Spawn\n");
  1729.                 if (attacker.classname == "monster_vomit")
  1730.                     bprint (" was vomited on by a Vomitus\n");
  1731.                 if (attacker.classname == "monster_wizard")
  1732.                     bprint (" was scragged by a Scrag\n");
  1733.                 if (attacker.classname == "monster_zombie")
  1734.                     bprint (" joins the Zombies\n");
  1735.  
  1736.                 return;
  1737.             }
  1738.             if (attacker.classname == "explo_box")
  1739.             {
  1740.                 bprint (" blew up\n");
  1741.                 return;
  1742.             }
  1743.             if (attacker.solid == SOLID_BSP && attacker != world)
  1744.             {    
  1745.                 bprint (" was squished\n");
  1746.                 return;
  1747.             }
  1748.             if (targ.deathtype == "falling")
  1749.             {
  1750.                 targ.deathtype = "";
  1751.                 bprint (" fell to his death\n");
  1752.                 return;
  1753.             }
  1754.             if (attacker.classname == "trap_shooter" || attacker.classname == "trap_spikeshooter")
  1755.             {
  1756.                 bprint (" was spiked\n");
  1757.                 return;
  1758.             }
  1759.             if (attacker.classname == "fireball")
  1760.             {
  1761.                 bprint (" ate a lavaball\n");
  1762.                 return;
  1763.             }
  1764.             if (attacker.classname == "trigger_changelevel")
  1765.             {
  1766.                 bprint (" tried to leave\n");
  1767.                 return;
  1768.             }
  1769.  
  1770.             bprint (" died\n");
  1771.         }
  1772.     }
  1773. };
  1774.